import requests
import json

if __name__ == '__main__':
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
    }
    url = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList'
    data_list = []
    for page in range(1,6):
        page = str(page)
        data = {
            'on': 'true',
            'page': page,
            'pageSize': '15',
            'productName':'',
            'conditionType': '1',
            'applyname':'',
            'applysn':''
        }
        response = requests.post(url=url,data=data,headers=headers).json()
        for list in response['list']:
            data_list.append(list['ID'])
    url2 = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
    f = open('药监总局.json', 'w', encoding='utf-8')
    all_data_list = []
    for id in data_list:
        data2 = {
            'id': id
        }
        res = requests.post(url=url2,data=data2,headers=headers)
        json_data2 = res.json()
        all_data_list.append(json_data2)
    json.dump(all_data_list, f, ensure_ascii=False)
    f.close()
    print('爬取完毕！')
